 
package com.zdkj.subway.rca.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.in.SwCkStationDailyReportQueryDTO;
import com.zdkj.subway.rca.dto.out.SwCkStationDailyReportOriginalExcelDTO;
import com.zdkj.subway.rca.entity.SwCkStationDailyReportAdjust;
import com.zdkj.subway.rca.entity.SwCkStationDailyReportAdjustLog;
import com.zdkj.subway.rca.entity.SwCkStationDailyReportAdjustRecordLog;
import com.zdkj.subway.rca.entity.SwCkStationDailyReportOriginal;
import com.zdkj.subway.rca.mapper.SwCkStationDailyReportOriginalMapper;
import com.zdkj.subway.rca.service.SwCkStationDailyReportAdjustLogService;
import com.zdkj.subway.rca.service.SwCkStationDailyReportAdjustRecordLogService;
import com.zdkj.subway.rca.service.SwCkStationDailyReportAdjustService;
import com.zdkj.subway.rca.service.SwCkStationDailyReportOriginalService;
import com.zdkj.subway.rca.util.LocalDateConverter;
import com.zdkj.subway.rca.util.LocalDateTimeConverter;
import com.zdkj.subway.rca.util.MyDateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 报表调账-西安地铁票务收入日报原始表
 *
 * @author stw
 * @date 2020-11-21 21:38:48
 */
@Service
public class SwCkStationDailyReportOriginalServiceImpl extends ServiceImpl<SwCkStationDailyReportOriginalMapper, SwCkStationDailyReportOriginal> implements SwCkStationDailyReportOriginalService {
    private static final Logger log = LoggerFactory.getLogger(SwCkStationDailyReportOriginalServiceImpl.class);

	 private static final String sumStationCode = "999999";

    @Autowired
    private SwCkStationDailyReportAdjustService swCkStationDailyReportAdjustService;
    @Autowired
    private SwCkStationDailyReportAdjustLogService swCkStationDailyReportAdjustLogService;
    @Autowired
    private SwCkStationDailyReportAdjustRecordLogService swCkStationDailyReportAdjustRecordLogService;
    /**
     * 根据日期范围获取站点结算周期list
     */
    @Override
    public  List<Map<String,String>> getStationSettleCycleList(String startDate,String endDate){
        return this.baseMapper.getStationSettleCycleList(startDate, endDate);
    }

    /**
     * 产生日报表原始表
     * @return
     */
    @Override
    public Boolean generate(String startDate,String endDate,String lineCodes) throws Exception {
        log.info("---------------------1-------------------"+new Date());
        List<Map<String,String>> stationObjList = null;
        List<Map<String,String>> stationSettleCycleList = null;
        //如果线路不为null
        if(StringUtils.isNotEmpty(lineCodes)){
            stationObjList = this.baseMapper.selectStationMapByVlineCodes(lineCodes);
            stationSettleCycleList = this.baseMapper.getStationSettleCycleListByVlineCodes(startDate,endDate,lineCodes);

        }else {
            stationObjList = this.baseMapper.selectStationMap();
            //根据日期范围获取站点结算周期list
            stationSettleCycleList = this.baseMapper.getStationSettleCycleList(startDate,endDate);
        }

        List<String> listDate = MyDateUtil.getDatesBetweenTwoDate(startDate,endDate);


        
		//地铁日报表原始表数据对象
		List<SwCkStationDailyReportOriginal> insertList = new ArrayList<>();

        PigxUser user = SecurityUtils.getUser();
		//地铁日报表调账表数据对象
		List<SwCkStationDailyReportAdjust> ajustList =  new ArrayList<>();

        //根据日期存储线路汇总金额，key:  lineid+","+日期  原始表合计值
		Map<String,SwCkStationDailyReportOriginal> mapSumLine = new HashMap<String,SwCkStationDailyReportOriginal>(); 

		 //根据日期存储线路汇总金额，key:  lineid+","+日期  调账表合计对象
		Map<String,SwCkStationDailyReportAdjust> mapAjustSumLine = new HashMap<String,SwCkStationDailyReportAdjust>();

        //-----TVM单程票电子    原始表  购票  统一使用购票+充值
        //List<Map<String,Object>> tvmOneTicketMapList = this.baseMapper.getTvmOneTicket(startDate,endDate);
         //-----TVM单程票电子   调账表 购票+充值
		List<Map<String,Object>> tvmOneTicketAjustMapList = this.baseMapper.getTvmOneTicketAjust(startDate,endDate);

		//BOM票款 POS机金额，按电子规则获取 暂时业务未定，先不查询
        // List<Map<String,Object>> bomOnePosAmountMapList = this.baseMapper.getBomOnePosAmount(startDate,endDate);
        //BOM支付宝单程票金额  原始表 购票
        List<Map<String,Object>> bomOneTicketAlipayMapList = this.baseMapper.getBomOneTicketAlipay(startDate,endDate);

		 //BOM支付宝单程票金额--调账表购票+充值使用  1,2,3,4,5条件
        List<Map<String,Object>> bomOneTicketAlipayAjustMapList = this.baseMapper.getBomOneTicketAlipayAjust(startDate,endDate);
       
		//BOM微信单程票金额
        List<Map<String,Object>> bomOneTicketWechatMapList = this.baseMapper.getBomOneTicketWechat(startDate,endDate);

		//BOM微信单程票金额--调账表使用  1,2,3,4,5条件
        List<Map<String,Object>> bomOneTicketWechatAjustMapList = this.baseMapper.getBomOneTicketWechatAjust(startDate,endDate);

        //------------日票电子金额
        List<Map<String,Object>> dailyTicketAlipayMapList = this.baseMapper.getDailyTicketAlipay(startDate,endDate);
        List<Map<String,Object>> dailyTicketWechatMapList = this.baseMapper.getDailyTicketWechat(startDate,endDate);
		List<Map<String,Object>> dailyTicketCatMapList = this.baseMapper.getDailyTicketCat(startDate,endDate);
        //--------------纪念票电子金额
        List<Map<String,Object>> commemorativeTicketAlipayMapList = this.baseMapper.getCommemorativeTicketAlipay(startDate,endDate);
        List<Map<String,Object>> commemorativeTicketWechatMapList = this.baseMapper.getCommemorativeTicketWechat(startDate,endDate);
        //----------------APP线上售卖
        List<Map<String,Object>> appCommemorativeTicketMapList = this.baseMapper.getAppCommemorativeTicket(startDate,endDate);
        //长安通Bom支付宝充值金额
        List<Map<String,Object>> catTicketBomAlipayMapList = this.baseMapper.getCatTicketBomAlipay(startDate,endDate);

        //长安通Bom微信充值金额
        List<Map<String,Object>> catTicketBomWechatMapList = this.baseMapper.getCatTicketBomWechat(startDate,endDate);

        //长安通ITVM支付宝充值金额
        List<Map<String,Object>> catTicketItvmAlipayMapList = this.baseMapper.getCatTicketItvmAlipay(startDate,endDate);
        //长安通ITVM微信充值金额
        List<Map<String,Object>> catTicketItvmWechatMapList = this.baseMapper.getCatTicketItvmWechat(startDate,endDate);
        //长安通Itvm建行充值金额
        List<Map<String,Object>> catTicketItvmBankMapList = this.baseMapper.getCatTicketItvmBank(startDate,endDate);
        //----网络售票 电子  互联网售票机金额  20240204去掉网络售票项
        //List<Map<String,Object>> onlineTicketSalesMapList = this.baseMapper.getOnlineTicketSales(startDate,endDate);
        //----------二维码相关数据-------
        List<Map<String,Object>> qrCodeTicketMapList = this.baseMapper.getQrCodeTicket(startDate,endDate);
		List<Map<String,Object>> qrCodeTicketAppAmountList = this.baseMapper.getQrCodeTicketApp(startDate,endDate);
		List<Map<String,Object>> qrCodeTicketWechatappDiscountAmountList = this.baseMapper.getQrCodeTicketWechatappDiscount(startDate,endDate);//微信小程序优惠票，赋值给2号线北苑车站

        //----------------人脸--------------
        List<Map<String,Object>> faceRecognitionTicketBankMapList = this.baseMapper.getFaceRecognitionTicketBank(startDate,endDate);

		//----------应急及互联互通相关数据-------
        List<Map<String,Object>> qrConnectivityMapList = this.baseMapper.getQrConnectivity(startDate,endDate);
        //现金缴款单
        List<Map<String,Object>> bankCashPaymentNoteMapList = this.baseMapper.getBankCashPaymentNote(startDate,endDate);

        //补车站票款短款
        List<Map<String,Object>> stationCompensationMapList = this.baseMapper.getStationCompensation(startDate,endDate);

        BigDecimal decimal = new BigDecimal("0");
        //循环车站列表
        for (Map<String,String> stationMap : stationObjList) {
            String lineCode = stationMap.get("LINE_CODE");
            String stationCode = stationMap.get("CODE");
			String vLineCode =  stationMap.get("VLINE_CODE"); //区分一二期的标识 目前只包括西安地铁和西咸的线车站
            //循环时间段内每一天
            for(String settleDate : listDate) {
                Map<String,String> stationSettleCycleMap = findStationSettleCycleMap(lineCode,stationCode,settleDate,stationSettleCycleList);
                
                SwCkStationDailyReportOriginal insertObj = new SwCkStationDailyReportOriginal();//原始表对象
				SwCkStationDailyReportAdjust ajustObj = new SwCkStationDailyReportAdjust();  //调账表对象  
				
				LocalDate settleEndTime = LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")) ;
				insertObj.setTradeDate(settleEndTime);
                insertObj.setLineCode(lineCode);
                insertObj.setStationCode(stationCode);
				insertObj.setVlineCode(vLineCode);
				insertObj.setDeptId(user.getDeptId());
                insertObj.setCreatorId(user.getId());
                insertObj.setCreatorName(user.getNikeName());
                
                //电子的以及现金缴款单、补车站票款短款的根据日期直接获取  ----begin------
                //-----TVM单程票电子
                //TVM支付宝单程票金额
                insertObj.setTvmOneTicketAlipay(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketAlipay"));
                //TVM微信单程票金额
                insertObj.setTvmOneTicketWechat(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketWechat"));
                //TVM银行单程票金额
                insertObj.setTvmOneTicketBank(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketBank"));
                
                //---------BOM单程票电子金额
                //BOM 票款 POS机金额 暂时业务未定，先不设置 20240530
				//  insertObj.setBomOnePosAmount(getLongValue(bomOnePosAmountMapList,stationCode,lineCode,settleDate,"bomOnePosAmount"));
				//BOM支付宝单程票金
                insertObj.setBomOneTicketAlipay(getLongValue(bomOneTicketAlipayMapList,stationCode,lineCode,settleDate,"bomOneTicketAlipay"));
                //BOM微信单程票金额
                insertObj.setBomOneTicketWechat(getLongValue(bomOneTicketWechatMapList,stationCode,lineCode,settleDate,"bomOneTicketWechat"));
                 
                //------------日票电子金额
                //日票支付宝其他车票金额
                insertObj.setDailyTicketAlipay(getLongValue(dailyTicketAlipayMapList,stationCode,lineCode,settleDate,"dailyTicketAlipay"));
                //日票微信其他票种金额
                insertObj.setDailyTicketWechat(getLongValue(dailyTicketWechatMapList,stationCode,lineCode,settleDate,"dailyTicketWechat"));

				//长安通日票代售金额,是否按电子的计算待定
				insertObj.setDailyTicketCat(0L); //放到2号线运动公园车站 每天读取设置。				
				if(lineCode.equals("2") && stationCode.equals("25")){
				   insertObj.setDailyTicketCat(getLongValue(dailyTicketCatMapList,stationCode,lineCode,settleDate,"dailyTicketCat"));			
				}
                
                //--------------纪念票电子金额
                //纪念票支付宝其他车票金额
                insertObj.setCommemorativeTicketAlipay(getLongValue(commemorativeTicketAlipayMapList,stationCode,lineCode,settleDate,"commemorativeTicketAlipay"));

                //纪念票微信其他车票金额
                insertObj.setCommemorativeTicketWechat(getLongValue(commemorativeTicketWechatMapList,stationCode,lineCode,settleDate,"commemorativeTicketWechat"));

                //----------------APP线上售卖
                //APP纪念票金额
                insertObj.setAppCommemorativeTicket(getLongValue(appCommemorativeTicketMapList,stationCode,lineCode,settleDate,"appCommemorativeTicket"));

                //长安通Bom支付宝充值金额
                insertObj.setCatTicketAlipay(getLongValue(catTicketBomAlipayMapList,stationCode,lineCode,settleDate,"catTicketBomAlipay"));

                //长安通Bom微信充值金额
                insertObj.setCatTicketWechat(getLongValue(catTicketBomWechatMapList,stationCode,lineCode,settleDate,"catTicketBomWechat"));

                //长安通ITVM支付宝充值金额
                insertObj.setCatTicketItvmAlipay(getLongValue(catTicketItvmAlipayMapList,stationCode,lineCode,settleDate,"catTicketItvmAlipay"));

                //长安通ITVM微信充值金额
                insertObj.setCatTicketItvmWechat(getLongValue(catTicketItvmWechatMapList,stationCode,lineCode,settleDate,"catTicketItvmWechat"));

                //长安通Itvm建行充值金额
                insertObj.setCatTicketItvmBank(getLongValue(catTicketItvmBankMapList,stationCode,lineCode,settleDate,"catTicketItvmBank"));
                
                //----网络售票 电子  互联网售票机金额  20240204 去掉此项设置
                //网络售票
                //insertObj.setOnlineTicketSales(getLongValue(onlineTicketSalesMapList,stationCode,lineCode,settleDate,"onlineTicketSales"));
				insertObj.setOnlineTicketSales(0L);
                
              //----------二维码相关数据-------

                //二维码支付宝金额
                insertObj.setQrCodeTicketAlipay(getLongValue(qrCodeTicketMapList,stationCode,lineCode,settleDate,"qrCodeTicketAlipay"));
                //二维码微信金额
                insertObj.setQrCodeTicketWechat(getLongValue(qrCodeTicketMapList,stationCode,lineCode,settleDate,"qrCodeTicketWechat"));
                //二维码银联金额
                insertObj.setQrCodeTicketUnionpay(getLongValue(qrCodeTicketMapList,stationCode,lineCode,settleDate,"qrCodeTicketUnionpay"));
				//二维码微信小程序金额
                insertObj.setQrCodeTicketWechatapp(getLongValue(qrCodeTicketMapList,stationCode,lineCode,settleDate,"qrCodeTicketWechatapp"));
                //智码APP代售以及微信小程序优惠,只是赋值给2号线北苑站,且是每天处理
				insertObj.setQrCodeTicketApp(0L);
				insertObj.setQrCodeTicketWechatappDiscount(0L);
				if(lineCode.equals("2") && stationCode.equals("23")){
				   insertObj.setQrCodeTicketApp(getLongValue(qrCodeTicketAppAmountList,stationCode,lineCode,settleDate,"qrCodeTicketApp"));
				   insertObj.setQrCodeTicketWechatappDiscount(getLongValue(qrCodeTicketWechatappDiscountAmountList,stationCode,lineCode,settleDate,"qrCodeTicketWechatappDiscount"));
				}
				//20240530增加POS机相关数据，默认都是0
				insertObj.setBomOnePosAmount(0L);
				insertObj.setPrefabricatedTicketPosAmount(0L);
				insertObj.setDailyTicketPosAmount(0L);
				insertObj.setCommemorativeTicketPosAmount(0L);
				insertObj.setCatTicketPosAmount(0L);
				

				
				/*
				//智码APP代售
				insertObj.setQrCodeTicketApp(0L); //只有是每个月的最后一天，从导入的对账确认表内获取对应的金额，放到2号线北苑车站和合计项内。
				int iDate = Integer.parseInt(settleDate.substring(8,10));
		        boolean isLastDay = (iDate==Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH));
				if(lineCode.equals("2") && stationCode.equals("23")&& isLastDay){				     
				   Map<String,Long> qrCodeTicketAppAmountMap = this.baseMapper.getQrCodeTicketApp(settleDate);
				   insertObj.setQrCodeTicketApp(qrCodeTicketAppAmountMap.get("qrCodeTicketApp"));			
				}
				*/
                //二维码小计
                insertObj.setQrCodeSubTotal(insertObj.getQrCodeTicketAlipay() + insertObj.getQrCodeTicketWechat() + insertObj.getQrCodeTicketUnionpay() + insertObj.getQrCodeTicketApp() + insertObj.getQrCodeTicketWechatapp() + insertObj.getQrCodeTicketWechatappDiscount());
               
                
                //----------------人脸--------------
                //人脸识别银行金额
                insertObj.setFaceRecognitionTicketBank(getLongValue(faceRecognitionTicketBankMapList,stationCode,lineCode,settleDate,"faceRecognitionTicketBank"));

				//应急及互联互通
				 //二维码支付宝金额
                insertObj.setQrConnectivityAlipay(getLongValue(qrConnectivityMapList,stationCode,lineCode,settleDate,"qrConnectivityAlipay"));
                //二维码微信金额
                insertObj.setQrConnectivityWechat(getLongValue(qrConnectivityMapList,stationCode,lineCode,settleDate,"qrConnectivityWechat"));
				insertObj.setQrConnectivitySubTotal(insertObj.getQrConnectivityAlipay() + insertObj.getQrConnectivityWechat());
                
              //现金缴款单
                Long bankCashPaymentNoteLong = getLongValue(bankCashPaymentNoteMapList,stationCode,lineCode,settleDate,"bankCashPaymentNote");

                //补车站票款短款
                insertObj.setStationCompensation(getLongValue(stationCompensationMapList,stationCode,lineCode,settleDate,"stationCompensation"));

              //电子的根据日期直接获取----end------
                //复制原始表的属性到调账表    上面的数据可以直接复制过来   ---确认
				BeanUtils.copyProperties(insertObj,ajustObj);  
				if(stationSettleCycleMap != null) {//属于结算日的处理，只计算现金部分的
                    String beginDate = stationSettleCycleMap.get("beginDate");

                    LocalDate settleBeginTime = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")) ;       
                    insertObj.setSettleBeginTime(settleBeginTime);
                    insertObj.setSettleEndTime(settleEndTime);
                   
                    
                    //===============结账日取现金的要范围，其他直接放外面==========================  
					Map<String,Long> stationDailyReportMap = this.baseMapper.getStationDailyReport(insertObj);//车站营收日报表所有数据
                    //售票员收入审核表，获取预制单程票和应急纸票现金金额
					Map<String,Long> bomConductorAuditMap = this.baseMapper.getBomOneTicketCashAuditInfo(insertObj);
                   //预制票金额,从日报表直接获取
                    //Map<String,Long> prefabricatedTicketAmountMap = this.baseMapper.getPrefabricatedTicketAmount(insertObj);
                    //insertObj.setPrefabricatedTicketAmount(prefabricatedTicketAmountMap.get("prefabricatedTicketAmount"));
					//insertObj.setPrefabricatedTicketAmount(stationDailyReportMap.get("yzdcp"));
                    //20220819 预制票从审核表获取
                    insertObj.setPrefabricatedTicketAmount(bomConductorAuditMap.get("yzdcp"));
                    //应急票金额,从日报表直接获取
                    //Map<String,Long> emergencyTicketAmount = this.baseMapper.getEmergencyTicketAmount(insertObj);
                    //insertObj.setEmergencyTicketAmount(emergencyTicketAmount.get("emergencyTicketAmount"));
					//insertObj.setEmergencyTicketAmount(stationDailyReportMap.get("yjzp"));
					 //20220819 应急纸票从审核表获取
                    insertObj.setEmergencyTicketAmount(bomConductorAuditMap.get("yjzp"));
                    //计次票金额
                    Map<String,Long> ticketCountingMap = this.baseMapper.getTicketCounting(insertObj);
                    insertObj.setTicketCounting(ticketCountingMap.get("ticketCounting"));

                    //日票现金其他车票金额
                    Map<String,Long> dailyTicketCashMap = this.baseMapper.getDailyTicketCash(insertObj);
                    insertObj.setDailyTicketCash(dailyTicketCashMap.get("dailyTicketCash"));
                    
                  //纪念票现金其他车票金额
                    Map<String,Long> commemorativeTicketCashMap = this.baseMapper.getCommemorativeTicketCash(insertObj);
                    insertObj.setCommemorativeTicketCash(commemorativeTicketCashMap.get("commemorativeTicketCash"));
                    
                    //长安通Bom现金充值金额
                    Map<String,Long> catTicketBomCashMap = this.baseMapper.getCatTicketBomCash(insertObj);
                    insertObj.setCatTicketCash(catTicketBomCashMap.get("catTicketBomCash"));
                    
                    //长安通ITVM现金充值金额  该现金合并到长安通Bom现金充值金额里，不再单独查询
					 Map<String,Long> catTicketItvmCashMap = this.baseMapper.getCatTicketItvmCash(insertObj);//20210715调整
					/*
                    Map<String,Long> catTicketItvmCashMap = this.baseMapper.getCatTicketItvmCash(insertObj);
                    insertObj.setCatTicketItvmCash(catTicketItvmCashMap.get("catTicketItvmCash"));  
					*/
                    insertObj.setCatTicketItvmCash(0L);
                    //日票其他车票小计 20240530 增加POS
                    insertObj.setDailySubTotal(insertObj.getDailyTicketCash() +insertObj.getDailyTicketPosAmount()+ insertObj.getDailyTicketAlipay() + insertObj.getDailyTicketWechat()+ insertObj.getDailyTicketCat());       

                    //纪念票小计  20240530 增加POS
                    insertObj.setCommemorativeTicketSubTotal(insertObj.getCommemorativeTicketCash() + insertObj.getCommemorativeTicketPosAmount() +insertObj.getCommemorativeTicketAlipay() + insertObj. getCommemorativeTicketWechat());
					//长安通小计   20240530 增加POS
                    insertObj.setCatSubTotal(insertObj.getCatTicketCash()  + insertObj.getCatTicketPosAmount()+ insertObj.getCatTicketAlipay() + insertObj.getCatTicketWechat()
                            + insertObj.getCatTicketItvmCash()  + insertObj.getCatTicketItvmAlipay() + insertObj.getCatTicketItvmWechat() + insertObj.getCatTicketItvmBank());
					 //长安通刷卡消费  只体现在小计中，车站赋值为0
                    insertObj.setCatTicketPayCard(decimal);
                    
                   
                    //交通一卡通  只体现在小计中，车站赋值为0
                    insertObj.setAllOneTrafficCard(decimal);
                      //备用金解行
                    insertObj.setReleasePettyCash(0L);
                    
                    //----------复制通常的现金和小计总计
                    BeanUtils.copyProperties(insertObj,ajustObj);
                    
                    
                    //TVM现金单程票现金金额,20220802改为从审核表直接获取
                    Map<String,Long> tvmOneTicketCashMap = this.baseMapper.getTvmOneTicketCash(insertObj);
                    insertObj.setTvmOneTicketCash(tvmOneTicketCashMap.get("tvmOneTicketCash"));
					//insertObj.setTvmOneTicketCash(stationDailyReportMap.get("tvmOneTicketCash"));-- 20220802不从日报表获取
                    
                    //BOM现金单程票金额
                    Map<String,Long> bomOneTicketCashMap = this.baseMapper.getBomOneTicketCash(insertObj);
					//车站营收日报BOM实收-sc层级金额-日票现金-纪念票现金-预制-应急+补售票员短款+客值交接长款+其他票款长款  20220802改为从审核表+售票员补款表+车站日报表三个表获取
					//修改为售票员收入审核售票员票款差异审核同一收入日期审核通过实收金额—营销车票现金-乘客事务现金—预制—应急）+补售票员短款（售票员页面审核通过且已完成补款）+客值交接长款+其他票款长款（车站营收日报）
                   // insertObj.setBomOneTicketCash(bomOneTicketCashMap.get("bomOneTicketCash")-insertObj.getDailyTicketCash()-insertObj.getCommemorativeTicketCash()-insertObj.getPrefabricatedTicketAmount()-insertObj.getEmergencyTicketAmount()+stationDailyReportMap.get("conductorShort")+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));  
                    //insertObj.setBomOneTicketCash(bomOneTicketCashMap.get("bomOneTicketCash")+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));
					//20220819 BOM现金改为：原始表：实收【审核表】-日票现金【日报表本身有这个数据】-纪念票现金【日报表本身有这个数据】-预制【日报表本身有这个数据】-应急【日报表本身有这个数据】+审核通过的售票员补款+日报表交接长款+日报表其他票款
                    insertObj.setBomOneTicketCash(bomOneTicketCashMap.get("bomOneTicketCash")-insertObj.getDailyTicketCash()-insertObj.getCommemorativeTicketCash()-insertObj.getPrefabricatedTicketAmount()-insertObj.getEmergencyTicketAmount()+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));  
					 //调账表BOM票款查询 20210715
                    Map<String,Long> bomOneTicketSingleCashMap = this.baseMapper.getBomOneTicketAjustCash(insertObj);
					
                    //TVM发售小计
                    insertObj.setTvmSubTotal(insertObj.getTvmOneTicketCash() + insertObj.getTvmOneTicketAlipay() + insertObj.getTvmOneTicketWechat() + insertObj.getTvmOneTicketBank());
                    //BOM票款小计,增加POS机
                    insertObj.setBomSubTotal(insertObj.getBomOneTicketCash() + insertObj.getBomOnePosAmount() + insertObj.getBomOneTicketAlipay() + insertObj.getBomOneTicketWechat());

						
					//-------------单独设置调整表单的单程票TVM  和BOM票款  20210611 begin
					
					 //TVM支付宝单程票金额   购票+充值-ACC
					ajustObj.setTvmOneTicketAlipay(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketAlipay")-insertObj.getCatTicketItvmAlipay());
					//TVM微信单程票金额
					ajustObj.setTvmOneTicketWechat(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketWechat")-insertObj.getCatTicketItvmWechat());
					//TVM银行单程票金额
					ajustObj.setTvmOneTicketBank(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketBank")-insertObj.getCatTicketItvmBank());
					
					//---------BOM单程票电子金额
					//BOM支付宝单程票金
					ajustObj.setBomOneTicketAlipay(getLongValue(bomOneTicketAlipayAjustMapList,stationCode,lineCode,settleDate,"bomOneTicketAlipay")-insertObj.getCatTicketAlipay());
					//BOM微信单程票金额
					ajustObj.setBomOneTicketWechat(getLongValue(bomOneTicketWechatAjustMapList,stationCode,lineCode,settleDate,"bomOneTicketWechat")-insertObj.getCatTicketWechat());
					// ---------------end
                    
                    //属于结账日的，调账表现金部分用原始值-ACC接口
	                    //----------------------调账表单程票数据赋值------原始值-ACC接口----------开始
					    //TVM支付宝单程票金额
						//ajustObj.setTvmOneTicketCash(insertObj.getTvmOneTicketCash()-insertObj.getCatTicketItvmCash());	
						ajustObj.setTvmOneTicketCash(insertObj.getTvmOneTicketCash()-catTicketItvmCashMap.get("catTicketItvmCash"));//20210715调整
						//TVM支付宝单程票金额,电子的不需要减 
						//ajustObj.setTvmOneTicketAlipay(insertObj.getTvmOneTicketAlipay()-insertObj.getCatTicketItvmAlipay());		
						//TVM微信单程票金额
						//ajustObj.setTvmOneTicketWechat(insertObj.getTvmOneTicketWechat()-insertObj.getCatTicketItvmWechat());		
						//TVM银行单程票金额
						//ajustObj.setTvmOneTicketBank(insertObj.getTvmOneTicketBank()-insertObj.getCatTicketItvmBank());
						//TVM发售小计
						ajustObj.setTvmSubTotal(ajustObj.getTvmOneTicketCash() + ajustObj.getTvmOneTicketAlipay() + ajustObj.getTvmOneTicketWechat() + ajustObj.getTvmOneTicketBank());
	
					    //BOM支付宝单程票金额
						//车站营收日报BOM实收-acc层级金额-日票现金-纪念票现金-预制-应急+补售票员短款+客值交接长款+其他票款长款
                       //车站营收日报BOM实收-acc层级金额-日票现金-纪念票现金-预制-应急+补售票员短款+客值交接长款+其他票款长款  20220802改为从审核表+售票员补款表+车站日报表三个表获取
					//修改为售票员收入审核售票员票款差异审核同一收入日期审核通过实收金额—营销车票现金-乘客事务现金—预制—应急）+补售票员短款（售票员页面审核通过且已完成补款）+客值交接长款+其他票款长款（车站营收日报）
                        //ajustObj.setBomOneTicketCash(bomOneTicketSingleCashMap.get("bomOneTicketCash")+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));                
						//ajustObj.setBomOneTicketCash(bomOneTicketSingleCashMap.get("bomOneTicketCash")-ajustObj.getDailyTicketCash()-ajustObj.getCommemorativeTicketCash()-ajustObj.getPrefabricatedTicketAmount()-ajustObj.getEmergencyTicketAmount()+stationDailyReportMap.get("conductorShort")+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));	
						//BOM支付宝单程票金额 ,电子的不需要减   20210611  原始表每天只算1,2,4,5加起来导入的值，调账表每天算1,2,3,4,5-ACC接口每天的值			
						//ajustObj.setBomOneTicketAlipay(insertObj.getBomOneTicketAlipay()-insertObj.getCatTicketAlipay());
						//BOM微信单程票金额						
						//ajustObj.setBomOneTicketWechat(insertObj.getBomOneTicketWechat()-insertObj.getCatTicketWechat());	
                        //20220819 BOM现金改为：调账表：实收【审核表】-日票现金【日报表本身有这个数据】-纪念票现金【日报表本身有这个数据】-预制【日报表本身有这个数据】-应急【日报表本身有这个数据】+审核通过的售票员补款+日报表交接长款+日报表其他票款
                        ajustObj.setBomOneTicketCash(bomOneTicketSingleCashMap.get("bomOneTicketCash")-ajustObj.getDailyTicketCash()-ajustObj.getCommemorativeTicketCash()-ajustObj.getPrefabricatedTicketAmount()-ajustObj.getEmergencyTicketAmount()+stationDailyReportMap.get("conductorLong")+stationDailyReportMap.get("conductorOther"));  
						
						//BOM票款小计 ,增加POS机
						ajustObj.setBomSubTotal(ajustObj.getBomOneTicketCash()+ajustObj.getBomOnePosAmount() +ajustObj.getBomOnePosAmount() + ajustObj.getBomOneTicketAlipay() + ajustObj.getBomOneTicketWechat());
					
					
					//03-09  解行金额按Excel公式计算
					//公式：  TVM现金+BOM现金+预制票+应急纸票+计次票+日票现金+纪念票现金+长安通现金+车站票款现金长款+车站票款现金短款+补车站票款短款+备用金解行

					 //实收现金合计  TVM现金+BOM现金+预制票+应急纸票+计次票+日票现金+纪念票现金+长安通现金  +  补车站票款短款
					Long totalCash = insertObj.getTvmOneTicketCash() + insertObj.getBomOneTicketCash() + insertObj.getPrefabricatedTicketAmount()
                            + insertObj.getEmergencyTicketAmount() + insertObj.getTicketCounting() + insertObj.getDailyTicketCash() + insertObj.getCommemorativeTicketCash() +
                             insertObj.getCatTicketCash()+insertObj.getStationCompensation();
					
					Long ajustTotalCash = ajustObj.getTvmOneTicketCash() + ajustObj.getBomOneTicketCash() + ajustObj.getPrefabricatedTicketAmount()
                            + ajustObj.getEmergencyTicketAmount() + ajustObj.getTicketCounting() + ajustObj.getDailyTicketCash() + ajustObj.getCommemorativeTicketCash() +
                             ajustObj.getCatTicketCash()+ajustObj.getStationCompensation();
                    
					//20240530 增加POS小计
					Long subTotalPos = insertObj.getBomOnePosAmount() + insertObj.getPrefabricatedTicketPosAmount()	+ insertObj.getDailyTicketPosAmount()+ insertObj.getCommemorativeTicketPosAmount()+ insertObj.getCatTicketPosAmount();
					Long ajustSubTotalPos = ajustObj.getBomOnePosAmount() + ajustObj.getPrefabricatedTicketPosAmount()	+ ajustObj.getDailyTicketPosAmount()+ ajustObj.getCommemorativeTicketPosAmount()+ ajustObj.getCatTicketPosAmount();
                    insertObj.setSubTotaPos(subTotalPos);
					ajustObj.setSubTotaPos(ajustSubTotalPos);

					//车站票款长/短款 = 现金缴款单—（车站营收总金额+补车站票款短款+备用金误解行0）
					//车站票款长/短款 = 现金缴款单-车站营收总金额  20240519 公式调整
                    //Long diff = bankCashPaymentNoteLong - totalCash;
					//Long diffAjust = bankCashPaymentNoteLong - ajustTotalCash;
					//Long diff = bankCashPaymentNoteLong - (stationDailyReportMap.get("total") + insertObj.getStationCompensation()) ;  //20240519注释  
					//Long diff = bankCashPaymentNoteLong - stationDailyReportMap.get("total");  
					Long diff = bankCashPaymentNoteLong - stationDailyReportMap.get("total")-insertObj.getStationCompensation(); //20240731改公式  20241011 恢复

					log.info("---------------------获取车站票款长短款-------------------"+bankCashPaymentNoteLong+"----------"+stationDailyReportMap.get("total")+"--------"+insertObj.getStationCompensation());
					Long diffAjust = diff;
					
                    if (diff  >= 0) {
                        //车站票款现金长款
                        insertObj.setStationTicketLongCash(diff);
                        insertObj.setStationTicketShortCash(0L);
                    } else {
                        insertObj.setStationTicketLongCash(0L);
                        //车站票款现金短款
                        insertObj.setStationTicketShortCash(diff);
                    }
                    //计算调账表差异
					if (diffAjust  >= 0) {
                        //车站票款现金长款
                        ajustObj.setStationTicketLongCash(diffAjust);
                        ajustObj.setStationTicketShortCash(0L);
                    } else {
                        ajustObj.setStationTicketLongCash(0L);
                        //车站票款现金短款
                        ajustObj.setStationTicketShortCash(diffAjust);
                    }
					//现金合计  TVM现金+BOM现金+预制票+应急纸票+计次票+日票现金+纪念票现金+长安通现金+车站票款现金长款+车站票款现金短款+补车站票款短款+备用金解行  Excel文件里公式					
                   
					//解行金额  改为导入的现金缴款单  20210922
					//insertObj.setSettlementAmount(totalCash + diff);
					//ajustObj.setSettlementAmount(ajustTotalCash + diffAjust);
					    //解行金额 改为 导入的现金缴款单+补车站票款短款 20240519
                      
					//insertObj.setSettlementAmount(bankCashPaymentNoteLong);  20240519注释
					//ajustObj.setSettlementAmount(bankCashPaymentNoteLong);

					  //解行金额 改为 导入的现金缴款单+补车站票款短款 调整后
                   Long jiehangAmount = bankCashPaymentNoteLong +insertObj.getStationCompensation(); 
				   insertObj.setSettlementAmount(jiehangAmount);  
				   ajustObj.setSettlementAmount(jiehangAmount);
                    
                 			

                    //收入小计
                    /*insertObj.setSubTota(insertObj.getTvmOneTicketCash() + insertObj.getTvmOneTicketAlipay() + insertObj.getTvmOneTicketWechat() + insertObj.getTvmOneTicketBank() + insertObj.getBomOneTicketCash() +
                            insertObj.getBomOneTicketAlipay() + insertObj.getBomOneTicketWechat() + insertObj.getPrefabricatedTicketAmount() + insertObj.getEmergencyTicketAmount() + insertObj.getTicketCounting() +
                            insertObj.getDailyTicketCash() + insertObj.getDailyTicketAlipay() + insertObj.getDailyTicketWechat() + insertObj.getCommemorativeTicketCash() + insertObj.getCommemorativeTicketAlipay() +
                            insertObj.getCommemorativeTicketWechat() + insertObj.getAppCommemorativeTicket()
                    );*/ 
					
					//收入小计  TVM小计+BOM小计+ 预制票+应急纸票+计次票+日票小计+纪念票小计+APP纪念票+刷卡消费+网络售票+电子二维码小计+人脸+交通一卡通+车站票款长款  +应急互联互通小计

                    insertObj.setSubTota(new BigDecimal(String.valueOf(insertObj.getTvmSubTotal())).add(new BigDecimal(String.valueOf(insertObj.getBomSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getPrefabricatedTicketAmount()))).add(new BigDecimal(String.valueOf(insertObj.getPrefabricatedTicketPosAmount())))
                            .add(new BigDecimal(String.valueOf(insertObj.getEmergencyTicketAmount()))).add(new BigDecimal(String.valueOf(insertObj.getTicketCounting()))).add(new BigDecimal(String.valueOf(insertObj.getDailySubTotal())))
                            .add(new BigDecimal(String.valueOf(insertObj.getCommemorativeTicketSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getAppCommemorativeTicket()))).add(insertObj.getCatTicketPayCard())
                            .add(new BigDecimal(String.valueOf(insertObj.getOnlineTicketSales()))).add(new BigDecimal(String.valueOf(insertObj.getQrCodeSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getFaceRecognitionTicketBank())))
                            .add(new BigDecimal(String.valueOf(insertObj.getQrConnectivitySubTotal())))
					        .add(insertObj.getAllOneTrafficCard()).add(new BigDecimal(String.valueOf(insertObj.getStationTicketLongCash())))
                    );

					ajustObj.setSubTota(new BigDecimal(String.valueOf(ajustObj.getTvmSubTotal())).add(new BigDecimal(String.valueOf(ajustObj.getBomSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getPrefabricatedTicketAmount()))).add(new BigDecimal(String.valueOf(ajustObj.getPrefabricatedTicketPosAmount())))
                                    .add(new BigDecimal(String.valueOf(ajustObj.getEmergencyTicketAmount()))).add(new BigDecimal(String.valueOf(ajustObj.getTicketCounting()))).add(new BigDecimal(String.valueOf(ajustObj.getDailySubTotal())))
                                    .add(new BigDecimal(String.valueOf(ajustObj.getCommemorativeTicketSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getAppCommemorativeTicket()))).add(ajustObj.getCatTicketPayCard())
                                    .add(new BigDecimal(String.valueOf(ajustObj.getOnlineTicketSales()))).add(new BigDecimal(String.valueOf(ajustObj.getQrCodeSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getFaceRecognitionTicketBank())))
                                    .add(new BigDecimal(String.valueOf(ajustObj.getQrConnectivitySubTotal())))
					                .add(ajustObj.getAllOneTrafficCard()).add(new BigDecimal(String.valueOf(ajustObj.getStationTicketLongCash())))
                    );
				 
                    insertObj.setConfirmStatus("0");
					ajustObj.setConfirmStatus("0");
					 //插入或者更新按线路每日汇总值
                    insertOrUpdateDaySum(mapSumLine,insertObj);
					insertOrUpdateAjustDaySum(mapAjustSumLine,insertObj,ajustObj);
                   
					//将VlineCode恢复到LINEcode中
					insertObj.setLineCode(insertObj.getVlineCode());
					ajustObj.setLineCode(ajustObj.getVlineCode());
                    
					//更新之后再插入到保存对象中
					insertList.add(insertObj);
					ajustList.add(ajustObj);
					

            } else {//不属于结算日的，按现金金额置0，其他电子的照常获取
//                    SwCkStationDailyReportOriginal insertObj = new SwCkStationDailyReportOriginal();
//					SwCkStationDailyReportAdjust ajustObj = new SwCkStationDailyReportAdjust();
//                    insertObj.setTradeDate(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
//                    insertObj.setLineCode(lineCode);
//                    insertObj.setVlineCode(vLineCode);
//                    insertObj.setStationCode(stationCode);

                    //假如已经存在数据则返回
                   /* if (this.count(Wrappers.query(insertObj)) > 0){
                        existList.add(insertObj); 
                    }*/

                    insertObj.setSettleBeginTime(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                    insertObj.setSettleEndTime(LocalDate.parse(settleDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"))); 
                    insertObj.setTvmOneTicketCash(0L);
                    //TVM发售小计
                    insertObj.setTvmSubTotal(insertObj.getTvmOneTicketCash() + insertObj.getTvmOneTicketAlipay() + insertObj.getTvmOneTicketWechat() + insertObj.getTvmOneTicketBank());
                    insertObj.setBomOneTicketCash(0L);
					
                    //BOM票款小计
                    insertObj.setBomSubTotal(insertObj.getBomOneTicketCash()+insertObj.getBomOnePosAmount() + insertObj.getBomOneTicketAlipay() + insertObj.getBomOneTicketWechat());
                    
                    insertObj.setPrefabricatedTicketAmount(0L);
                    insertObj.setEmergencyTicketAmount(0L);
                    insertObj.setTicketCounting(0L);
                    
                    insertObj.setDailyTicketCash(0L);
                    //日票其他车票小计
                    insertObj.setDailySubTotal(insertObj.getDailyTicketCash()+insertObj.getDailyTicketPosAmount() + insertObj.getDailyTicketAlipay() + insertObj.getDailyTicketWechat() + insertObj.getDailyTicketCat());       
                    
                    insertObj.setCommemorativeTicketCash(0L);
                    //纪念票小计
                    insertObj.setCommemorativeTicketSubTotal(insertObj.getCommemorativeTicketCash()+insertObj.getCommemorativeTicketPosAmount() + insertObj.getCommemorativeTicketAlipay() + insertObj. getCommemorativeTicketWechat());
                    
                    insertObj.setCatTicketCash(0L);
                    insertObj.setCatTicketItvmCash(0L);
                    //长安通小计
                    insertObj.setCatSubTotal(insertObj.getCatTicketCash() +insertObj.getCatTicketPosAmount() + insertObj.getCatTicketAlipay() + insertObj.getCatTicketWechat()
                            + insertObj.getCatTicketItvmCash()  + insertObj.getCatTicketItvmAlipay() + insertObj.getCatTicketItvmWechat() + insertObj.getCatTicketItvmBank());
                 			
                    insertObj.setCatTicketPayCard(decimal);
                    insertObj.setReleasePettyCash(0L);
					
                    insertObj.setAllOneTrafficCard(decimal);
                    insertObj.setConfirmStatus("0");
                    //复制原始表的属性到调账表    上面的数据可以直接复制过来   ---确认。。。 
					BeanUtils.copyProperties(insertObj,ajustObj);


					//-------------单独设置调整表单的单程票TVM  和BOM票款  20210611 begin
					
					 //TVM支付宝单程票金额   购票+充值-ACC
					ajustObj.setTvmOneTicketAlipay(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketAlipay")-insertObj.getCatTicketItvmAlipay());
					//TVM微信单程票金额
					ajustObj.setTvmOneTicketWechat(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketWechat")-insertObj.getCatTicketItvmWechat());
					//TVM银行单程票金额
					ajustObj.setTvmOneTicketBank(getLongValue(tvmOneTicketAjustMapList,stationCode,lineCode,settleDate,"tvmOneTicketBank")-insertObj.getCatTicketItvmBank());
					
					ajustObj.setTvmSubTotal(ajustObj.getTvmOneTicketCash() + ajustObj.getTvmOneTicketAlipay() + ajustObj.getTvmOneTicketWechat() + ajustObj.getTvmOneTicketBank());
					
					//---------BOM单程票电子金额
					//BOM支付宝单程票金
					ajustObj.setBomOneTicketAlipay(getLongValue(bomOneTicketAlipayAjustMapList,stationCode,lineCode,settleDate,"bomOneTicketAlipay")-insertObj.getCatTicketAlipay());
					//BOM微信单程票金额
					ajustObj.setBomOneTicketWechat(getLongValue(bomOneTicketWechatAjustMapList,stationCode,lineCode,settleDate,"bomOneTicketWechat")-insertObj.getCatTicketWechat());
                    ajustObj.setBomSubTotal(ajustObj.getBomOneTicketCash() +ajustObj.getBomOnePosAmount()+ ajustObj.getBomOneTicketAlipay() + ajustObj.getBomOneTicketWechat());

                    
                	Long totalCash = insertObj.getTvmOneTicketCash() + insertObj.getBomOneTicketCash() + insertObj.getPrefabricatedTicketAmount()
                            + insertObj.getEmergencyTicketAmount() + insertObj.getTicketCounting() + insertObj.getDailyTicketCash() + insertObj.getCommemorativeTicketCash() +
                             insertObj.getCatTicketCash()+insertObj.getStationCompensation();
					
					Long ajustTotalCash = ajustObj.getTvmOneTicketCash() + ajustObj.getBomOneTicketCash() + ajustObj.getPrefabricatedTicketAmount()
                            + ajustObj.getEmergencyTicketAmount() + ajustObj.getTicketCounting() + ajustObj.getDailyTicketCash() + ajustObj.getCommemorativeTicketCash() +
                             ajustObj.getCatTicketCash()+ajustObj.getStationCompensation();
					
					Map<String,Long> stationDailyReportMap = this.baseMapper.getStationDailyReport(insertObj);//车站营收日报表所有数据

					//20240530 增加POS小计
					Long subTotalPos = insertObj.getBomOnePosAmount() + insertObj.getPrefabricatedTicketPosAmount()	+ insertObj.getDailyTicketPosAmount()+ insertObj.getCommemorativeTicketPosAmount()+ insertObj.getCatTicketPosAmount();
					Long ajustSubTotalPos = ajustObj.getBomOnePosAmount() + ajustObj.getPrefabricatedTicketPosAmount()	+ ajustObj.getDailyTicketPosAmount()+ ajustObj.getCommemorativeTicketPosAmount()+ ajustObj.getCatTicketPosAmount();
                    insertObj.setSubTotaPos(subTotalPos);
					ajustObj.setSubTotaPos(ajustSubTotalPos);

					 //车站票款长/短款 = 现金缴款单—（车站营收总金额+补车站票款短款+备用金误解行0）
                    //Long diff = bankCashPaymentNoteLong - totalCash;
					//Long diffAjust = bankCashPaymentNoteLong - ajustTotalCash;
					
					//非结算日，长短款都设置为0  20210929
					//Long diff = bankCashPaymentNoteLong - (stationDailyReportMap.get("total")+insertObj.getStationCompensation());
					Long diff = 0L;
					Long diffAjust = diff;                   
					
                    if (diff  >= 0) {
                        //车站票款现金长款
                        insertObj.setStationTicketLongCash(diff);
                        insertObj.setStationTicketShortCash(0L);
                    } else {
                        insertObj.setStationTicketLongCash(0L);
                        //车站票款现金短款
                        insertObj.setStationTicketShortCash(diff);
                    }
                    //计算调账表差异
					if (diffAjust  >= 0) {
                        //车站票款现金长款
                        ajustObj.setStationTicketLongCash(diffAjust);
                        ajustObj.setStationTicketShortCash(0L);
                    } else {
                        ajustObj.setStationTicketLongCash(0L);
                        //车站票款现金短款
                        ajustObj.setStationTicketShortCash(diffAjust);
                    }
								
                   //解行金额  改为导入的现金缴款单  20210922
					//insertObj.setSettlementAmount(totalCash + diff);
					//ajustObj.setSettlementAmount(ajustTotalCash + diffAjust);

					//insertObj.setSettlementAmount(bankCashPaymentNoteLong);  20240519注释
					//ajustObj.setSettlementAmount(bankCashPaymentNoteLong);

					  //解行金额 改为 导入的现金缴款单+补车站票款短款 调整后
                   Long jiehangAmount = bankCashPaymentNoteLong +insertObj.getStationCompensation(); 
				   insertObj.setSettlementAmount(jiehangAmount);  
				   ajustObj.setSettlementAmount(jiehangAmount);
										

                    insertObj.setSubTota(new BigDecimal(String.valueOf(insertObj.getTvmSubTotal())).add(new BigDecimal(String.valueOf(insertObj.getBomSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getPrefabricatedTicketAmount()))).add(new BigDecimal(String.valueOf(insertObj.getPrefabricatedTicketPosAmount())))
                            .add(new BigDecimal(String.valueOf(insertObj.getEmergencyTicketAmount()))).add(new BigDecimal(String.valueOf(insertObj.getTicketCounting()))).add(new BigDecimal(String.valueOf(insertObj.getDailySubTotal())))
                            .add(new BigDecimal(String.valueOf(insertObj.getCommemorativeTicketSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getAppCommemorativeTicket()))).add(insertObj.getCatTicketPayCard())
                            .add(new BigDecimal(String.valueOf(insertObj.getOnlineTicketSales()))).add(new BigDecimal(String.valueOf(insertObj.getQrCodeSubTotal()))).add(new BigDecimal(String.valueOf(insertObj.getFaceRecognitionTicketBank())))
                            .add(new BigDecimal(String.valueOf(insertObj.getQrConnectivitySubTotal())))
					        .add(insertObj.getAllOneTrafficCard()).add(new BigDecimal(String.valueOf(insertObj.getStationTicketLongCash())))
                    );

                    ajustObj.setSubTota(new BigDecimal(String.valueOf(ajustObj.getTvmSubTotal())).add(new BigDecimal(String.valueOf(ajustObj.getBomSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getPrefabricatedTicketAmount()))).add(new BigDecimal(String.valueOf(ajustObj.getPrefabricatedTicketPosAmount())))
                            .add(new BigDecimal(String.valueOf(ajustObj.getEmergencyTicketAmount()))).add(new BigDecimal(String.valueOf(ajustObj.getTicketCounting()))).add(new BigDecimal(String.valueOf(ajustObj.getDailySubTotal())))
                            .add(new BigDecimal(String.valueOf(ajustObj.getCommemorativeTicketSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getAppCommemorativeTicket()))).add(ajustObj.getCatTicketPayCard())
                            .add(new BigDecimal(String.valueOf(ajustObj.getOnlineTicketSales()))).add(new BigDecimal(String.valueOf(ajustObj.getQrCodeSubTotal()))).add(new BigDecimal(String.valueOf(ajustObj.getFaceRecognitionTicketBank())))
                            .add(new BigDecimal(String.valueOf(ajustObj.getQrConnectivitySubTotal())))
					        .add(ajustObj.getAllOneTrafficCard()).add(new BigDecimal(String.valueOf(ajustObj.getStationTicketLongCash())))
                    );
                   
					//插入或者更新按线路每日汇总值
                    insertOrUpdateDaySum(mapSumLine,insertObj);     
					//插入或者更新按线路每日汇总值
                    insertOrUpdateAjustDaySum(mapAjustSumLine,insertObj,ajustObj);
                   
					//将VlineCode恢复到LINEcode中
					insertObj.setLineCode(insertObj.getVlineCode());
					ajustObj.setLineCode(ajustObj.getVlineCode());
					
					insertList.add(insertObj);
					ajustList.add(ajustObj);

                }

            }

        }

        if(!insertList.isEmpty()){
			//----------------------原始表处理--------------------------------------------------
			 //  遍历每条线路的总计数据，合并一起加入
             Iterator<Map.Entry<String, SwCkStationDailyReportOriginal>> it = mapSumLine.entrySet().iterator();
             while (it.hasNext()) {
                 Map.Entry<String, SwCkStationDailyReportOriginal> entry = it.next();
                 SwCkStationDailyReportOriginal entryValue = entry.getValue();
                 entryValue.setSubTota(entryValue.getSubTota().add(entryValue.getAllOneTrafficCard()).add(entryValue.getCatTicketPayCard()));
                 insertList.add(entryValue);
             }
            // 1. 循环遍历listDate，线路和站点，以上三个条件，先删除原有的数据，再执行插入 日报表原始表
            //开始日期和结束日期 为TRADE_DATE
            //delete from sw_ck_station_daily_report_original where  TRADE_DATE>=startDate and TRADE_DATE<= endDate;
            this.remove(Wrappers.<SwCkStationDailyReportOriginal>lambdaQuery()
                    .between(SwCkStationDailyReportOriginal::getTradeDate,startDate,endDate)
                    .in(StringUtils.isNotEmpty(lineCodes),SwCkStationDailyReportOriginal::getLineCode,lineCodes.split(",")));
            this.saveBatch(insertList);
            //-------------------调账表处理----------------------------------------------------
			// 2. 循环遍历listDate，线路和站点，以上三个条件，先删除原有的调账表未确认的，再执行插入
            //delete from sw_ck_station_daily_report_adjust where  TRADE_DATE>=startDate and TRADE_DATE<= endDate;
            /*20210723  调整为暂时不考虑确认状态问题，都统一删除再新增
			swCkStationDailyReportAdjustService.remove(Wrappers.<SwCkStationDailyReportAdjust>lambdaQuery()
                    .between(SwCkStationDailyReportAdjust::getTradeDate,startDate,endDate)
                    .eq(SwCkStationDailyReportAdjust::getConfirmStatus,"0"));

            Iterator<Map.Entry<String, SwCkStationDailyReportAdjust>> itAjust = mapAjustSumLine.entrySet().iterator();
             while (itAjust.hasNext()) {
                 Map.Entry<String, SwCkStationDailyReportAdjust> entry = itAjust.next();
                 SwCkStationDailyReportAdjust value = entry.getValue();
                 SwCkStationDailyReportAdjust one = swCkStationDailyReportAdjustService.getOne(Wrappers.<SwCkStationDailyReportAdjust>lambdaQuery()
                         .eq(SwCkStationDailyReportAdjust::getLineCode, value.getLineCode())
                         .eq(SwCkStationDailyReportAdjust::getStationCode, value.getStationCode())
                         .eq(SwCkStationDailyReportAdjust::getTradeDate, value.getTradeDate())
                         .eq(SwCkStationDailyReportAdjust::getConfirmStatus, "1")
                         .eq(SwCkStationDailyReportAdjust::getDelFlag, "0"));
                 Boolean b = true;
                 if(ObjectUtil.isEmpty(one)){
                     ajustList.add(entry.getValue());
                     b = false;
                 }
                 if(b){
                     ajustList.removeIf(x ->
                             x.getLineCode().equals(value.getLineCode()) &&
                                     x.getTradeDate().equals(value.getTradeDate())
                     );
                     //-----------------------------------日志表的处理
                     // 3. 循环遍历listDate，线路和站点，以上三个条件，只是删除原有的调账表日志表
                     //delete from sw_ck_station_daily_report_adjust_log where  TRADE_DATE>=startDate and TRADE_DATE<= endDate;
                     swCkStationDailyReportAdjustLogService.remove(Wrappers.<SwCkStationDailyReportAdjustLog>lambdaQuery()
                             .eq(SwCkStationDailyReportAdjustLog::getTradeDate,value.getTradeDate())
                             .eq(SwCkStationDailyReportAdjustLog::getLineCode,value.getLineCode()));
                 }



             }*/
            /*
			List<SwCkStationDailyReportAdjust> adjustList = new ArrayList<>();
            insertList.stream().forEach(x -> {
                SwCkStationDailyReportAdjust swCkStationDailyReportAdjust = new SwCkStationDailyReportAdjust();
                BeanUtils.copyProperties(x,swCkStationDailyReportAdjust);
                adjustList.add(swCkStationDailyReportAdjust);
            });*/


            LocalDateTime now = LocalDateTime.now();
            //线路为空删除所有日期范围内的数据，否则删除当前线路
            LambdaQueryWrapper<SwCkStationDailyReportAdjust> between = Wrappers.<SwCkStationDailyReportAdjust>lambdaQuery()
                    .between(SwCkStationDailyReportAdjust::getTradeDate, startDate, endDate)
                    .in(StringUtils.isNotEmpty(lineCodes),SwCkStationDailyReportAdjust::getLineCode,lineCodes.split(","));
            //查出要移除的数据和新生成的数据 放到记录表内
            List<SwCkStationDailyReportAdjust> adjustAllList = swCkStationDailyReportAdjustService.list(between);
            adjustAllList.forEach(x -> {
                x.setLogConductorCode(user.getUserCode());
                x.setLogConductorName(user.getNikeName());
                x.setLogTime(now);
            });
            //移除旧的数据
            swCkStationDailyReportAdjustService.remove(between);
			
			Iterator<Map.Entry<String, SwCkStationDailyReportAdjust>> itAjust = mapAjustSumLine.entrySet().iterator();
            while (itAjust.hasNext()) {
                 Map.Entry<String, SwCkStationDailyReportAdjust> entry = itAjust.next();
                SwCkStationDailyReportAdjust entryValue = entry.getValue();
                entryValue.setSubTota(entryValue.getSubTota().add(entryValue.getAllOneTrafficCard()).add(entryValue.getCatTicketPayCard()));
                ajustList.add(entryValue);
            }
            //添加新生成的数据
            swCkStationDailyReportAdjustService.saveBatch(ajustList);//调帐表保存
            //-----------------------------------日志表的处理
			// 3. 循环遍历listDate，线路和站点，以上三个条件，只是删除原有的调账表日志表
            //delete from sw_ck_station_daily_report_adjust_log where  TRADE_DATE>=startDate and TRADE_DATE<= endDate;
            swCkStationDailyReportAdjustLogService.remove(Wrappers.<SwCkStationDailyReportAdjustLog>lambdaQuery()
                    .between(SwCkStationDailyReportAdjustLog::getTradeDate,startDate,endDate)
                    .in(StringUtils.isNotEmpty(lineCodes),SwCkStationDailyReportAdjustLog::getLineCode,lineCodes.split(",")));

            //4.处理调账记录表的数据
            Map<String, List<SwCkStationDailyReportAdjust>> collect = adjustAllList.stream()
                    // 根据日期和线路进行分组
                    .collect(Collectors.groupingBy(item -> item.getTradeDate() + item.getLineCode(), Collectors.toList()));
            Set<String> keySet = collect.keySet();
            for (String key : keySet) {
                List<SwCkStationDailyReportAdjust> swCkStationDailyReportAdjustsList = collect.get(key);
                if(CollectionUtils.isNotEmpty(swCkStationDailyReportAdjustsList)){
                    String uuid = UUID.randomUUID().toString().toLowerCase();
                    swCkStationDailyReportAdjustsList.stream().forEach(x -> x.setLogGroupId(uuid));
                }
            }
            List<SwCkStationDailyReportAdjustRecordLog> recordLogList = new ArrayList<>();
            for (SwCkStationDailyReportAdjust adjust : adjustAllList) {
                SwCkStationDailyReportAdjustRecordLog recordLog = new SwCkStationDailyReportAdjustRecordLog();
                BeanUtils.copyProperties(adjust,recordLog);
                recordLogList.add(recordLog);
            }
            swCkStationDailyReportAdjustRecordLogService.saveBatch(recordLogList);
            log.info("-------------------2---------------------"+new Date());
            return true;
        } else {
            return false;
        }

    }


    private Map<String,String> findStationSettleCycleMap(String lineCode, String stationCode, String settleDate,List<Map<String,String>> stationSettleCycleList){
        if(stationSettleCycleList == null || stationSettleCycleList.isEmpty()) {
            return null;
        }
        for(Map<String,String> map : stationSettleCycleList) {
            if(lineCode.equals(map.get("lineCode")) && stationCode.equals(map.get("stationCode")) && settleDate.equals(map.get("settleDate"))){
                return map;
            }
        }
        return null;
    }


    @Override
    public List<SwCkStationDailyReportOriginal> listSwCkStationDailyReportOriginal(SwCkStationDailyReportQueryDTO dto) {
        return this.baseMapper.listSwCkStationDailyReportOriginal(dto);
    }

    @Override
    public void export(String startDate, String endDate,String lineCodes, HttpServletResponse response) throws ParseException {
        List<SwCkStationDailyReportOriginal> list  = this.baseMapper.listSwCkStationDailyReport(startDate,endDate,lineCodes);
        String[] split = lineCodes.split(",");
        for (int i = 0; i < split.length; i++) {
            if(split[i].length() == 1){
                lineCodes = split[i];
                break;
            }
            lineCodes = split[i];
        }
        List<Map<String,String>> stationMap = this.baseMapper.selectStationMap();
		String lineName = getExportLineName(stationMap,lineCodes);

        Map<Integer, List<SwCkStationDailyReportOriginalExcelDTO>> map = new HashMap<>();
        Map<Integer, LocalDate> mapLocalDate = new HashMap<>();
        if(CollectionUtils.isNotEmpty(list)){
            List<String> betweenTwoDate = MyDateUtil.getDatesBetweenTwoDate(startDate, endDate);
            for (int i = 0; i < betweenTwoDate.size(); i++) {
                String  currentDate = betweenTwoDate.get(i);
                LocalDate localCurrentDate = LocalDate.parse(currentDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
                int iDate = Integer.valueOf(currentDate.substring(currentDate.length() - 2));//当前日期后两位

                List<SwCkStationDailyReportOriginal> collect = list.stream().filter(x -> localCurrentDate.equals(x.getTradeDate())).collect(Collectors.toList());
                List<SwCkStationDailyReportOriginalExcelDTO> records  = new ArrayList<>();

                BigDecimal hundred = new BigDecimal(100);
                for(SwCkStationDailyReportOriginal obj : collect) {
                    SwCkStationDailyReportOriginalExcelDTO dto = new SwCkStationDailyReportOriginalExcelDTO();

                    String stationName = getExportStationName(stationMap,obj.getStationCode(),obj.getLineCode());
                    dto.setStationName(stationName);

                    dto.setTvmOneTicketCash(new BigDecimal(obj.getTvmOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setTvmOneTicketAlipay(new BigDecimal(obj.getTvmOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setTvmOneTicketWechat(new BigDecimal(obj.getTvmOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setTvmOneTicketBank(new BigDecimal(obj.getTvmOneTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setTvmSubTotal(new BigDecimal(obj.getTvmSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setBomOneTicketCash(new BigDecimal(obj.getBomOneTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setBomOnePosAmount(new BigDecimal(obj.getBomOnePosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setBomOneTicketAlipay(new BigDecimal(obj.getBomOneTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setBomOneTicketWechat(new BigDecimal(obj.getBomOneTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setBomSubTotal(new BigDecimal(obj.getBomSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setPrefabricatedTicketAmount(new BigDecimal(obj.getPrefabricatedTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setPrefabricatedTicketPosAmount(new BigDecimal(obj.getPrefabricatedTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setEmergencyTicketAmount(new BigDecimal(obj.getEmergencyTicketAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setTicketCounting(new BigDecimal(obj.getTicketCounting()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setDailyTicketCash(new BigDecimal(obj.getDailyTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setDailyTicketPosAmount(new BigDecimal(obj.getDailyTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setDailyTicketAlipay(new BigDecimal(obj.getDailyTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setDailyTicketWechat(new BigDecimal(obj.getDailyTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setDailyTicketCat(new BigDecimal(obj.getDailyTicketCat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setDailySubTotal(new BigDecimal(obj.getDailySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setCommemorativeTicketCash(new BigDecimal(obj.getCommemorativeTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setCommemorativeTicketPosAmount(new BigDecimal(obj.getCommemorativeTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCommemorativeTicketAlipay(new BigDecimal(obj.getCommemorativeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCommemorativeTicketWechat(new BigDecimal(obj.getCommemorativeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCommemorativeTicketSubTotal(new BigDecimal(obj.getCommemorativeTicketSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setAppCommemorativeTicket(new BigDecimal(obj.getAppCommemorativeTicket()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setCatTicketCash(new BigDecimal(obj.getCatTicketCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setCatTicketPosAmount(new BigDecimal(obj.getCatTicketPosAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketAlipay(new BigDecimal(obj.getCatTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketWechat(new BigDecimal(obj.getCatTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketItvmCash(new BigDecimal(obj.getCatTicketItvmCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketItvmAlipay(new BigDecimal(obj.getCatTicketItvmAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketItvmWechat(new BigDecimal(obj.getCatTicketItvmWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatTicketItvmBank(new BigDecimal(obj.getCatTicketItvmBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setCatSubTotal(new BigDecimal(obj.getCatSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setCatTicketPayCard(obj.getCatTicketPayCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setOnlineTicketSales(new BigDecimal(obj.getOnlineTicketSales()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setQrCodeTicketAlipay(new BigDecimal(obj.getQrCodeTicketAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setQrCodeTicketWechat(new BigDecimal(obj.getQrCodeTicketWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setQrCodeTicketUnionpay(new BigDecimal(obj.getQrCodeTicketUnionpay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setQrCodeTicketApp(new BigDecimal(obj.getQrCodeTicketApp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setQrCodeTicketWechatappDiscount(new BigDecimal(obj.getQrCodeTicketWechatappDiscount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setQrCodeTicketWechatapp(new BigDecimal(obj.getQrCodeTicketWechatapp()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setQrCodeSubTotal(new BigDecimal(obj.getQrCodeSubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setFaceRecognitionTicketBank(new BigDecimal(obj.getFaceRecognitionTicketBank()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
  				    
					dto.setQrConnectivityAlipay(new BigDecimal(obj.getQrConnectivityAlipay()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setQrConnectivityWechat(new BigDecimal(obj.getQrConnectivityWechat()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setQrConnectivitySubTotal(new BigDecimal(obj.getQrConnectivitySubTotal()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));

                    dto.setAllOneTrafficCard(obj.getAllOneTrafficCard().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setStationTicketLongCash(new BigDecimal(obj.getStationTicketLongCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setStationTicketShortCash(new BigDecimal(obj.getStationTicketShortCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setStationCompensation(new BigDecimal(obj.getStationCompensation()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setReleasePettyCash(new BigDecimal(obj.getReleasePettyCash()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
					dto.setSubTotaPos(new BigDecimal(obj.getSubTotaPos()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setSettlementAmount(new BigDecimal(obj.getSettlementAmount()).divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    dto.setSubTota(obj.getSubTota().divide(hundred,2,BigDecimal.ROUND_HALF_UP));
                    records.add(dto);
                }
                map.put(iDate,records);
                mapLocalDate.put(iDate,localCurrentDate);
            }
            InputStream excelTemplateIs = null;
            try {response.reset(); // 非常重要
                response.setContentType("application/vnd.ms-excel");
                response.setCharacterEncoding("utf-8");
                final String fileName = URLEncoder.encode("西安地铁票务收入日报原始表", "UTF-8");
                response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");

                // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
                // {} 代表普通变量 {.} 代表是list的变量

                excelTemplateIs = this.getClass().getResourceAsStream("/static/excel/template/export/SwCkStationDailyReportOriginalExcelTemplate.xlsx");

                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerConverter(new LocalDateTimeConverter()).registerConverter(new LocalDateConverter()).withTemplate(excelTemplateIs).build();

                for (Map.Entry<Integer, List<SwCkStationDailyReportOriginalExcelDTO>> integerListEntry : map.entrySet()) {
                    Integer key = integerListEntry.getKey();
                    List<SwCkStationDailyReportOriginalExcelDTO> value = integerListEntry.getValue();
                    // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行，然后下面的数据往后移动。默认 是false，会直接使用下一行，如果没有则创建。
                    // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了，所以慎用
                    // 简单的说 如果你的模板有list,且list不是最后一行，下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
                    // 如果数据量大 list不是最后一行 参照另一个
                    WriteSheet writeSheet = EasyExcel.writerSheet(key-1,String.valueOf(key)).build();
                    FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
                    excelWriter.fill(value, fillConfig, writeSheet);
                    Map<String, Object> mapDate = new HashMap<>();
                    mapDate.put("currDate", mapLocalDate.get(key));
					mapDate.put("lineName",lineName);
                    excelWriter.fill(mapDate,writeSheet);
                }
                excelWriter.finish();
            } catch (Exception e) {
                e.printStackTrace();
                log.error("导出西安地铁票务收入日报原始表错误");
            } finally {
                if(excelTemplateIs != null){
                    try {
                        excelTemplateIs.close();
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }

                }
            }
        }
    }

    @Override
    public List<Map<String, String>> getNoAudit(String lineCode, String tradeDate) {

        return this.baseMapper.getNoAudit(lineCode,tradeDate);
    }
   /*
    private String getStationName (List<Map<String,String>> stationMap,String stationCode,String lineCode) {
        for (Map<String,String> map : stationMap){
            if(stationCode.equals(map.get("CODE")) && lineCode.equals(map.get("LINE_CODE"))){
                return map.get("NAME");
            }
        }
        return "";
    }*/

	private String getExportStationName (List<Map<String,String>> stationMap,String stationCode,String lineCode) {
        if(sumStationCode.equals(stationCode)){
            return "合计";
        }
        for (Map<String,String> map : stationMap) {
            if(stationCode.equals(map.get("CODE")) && lineCode.equals(map.get("VLINE_CODE"))) {
                return map.get("NAME");
            }
        }
        return "";
    }

	private String getExportLineName (List<Map<String,String>> stationMap,String lineCode) {
           for (Map<String,String> map : stationMap) {
            if(lineCode.equals(map.get("VLINE_CODE"))) {
                return map.get("SECOND_NAME");
            }
        }
        return "";
    }
    
	//调账表的更新
	private void insertOrUpdateAjustDaySum(Map<String,SwCkStationDailyReportAdjust> mapSumLine,SwCkStationDailyReportOriginal initObj,SwCkStationDailyReportAdjust insertObj){
	  //根据线路和日期获取汇总表的合计对象
		 boolean isExist = true;
		 SwCkStationDailyReportAdjust swCkStationDailyReportOriginalSum = mapSumLine.get(insertObj.getVlineCode()+","+insertObj.getTradeDate());
		 
		 if(swCkStationDailyReportOriginalSum ==null){
		    //不存在准备基本数据
			swCkStationDailyReportOriginalSum = new   SwCkStationDailyReportAdjust();	
            swCkStationDailyReportOriginalSum.setLineCode(insertObj.getVlineCode());
			swCkStationDailyReportOriginalSum.setStationCode(sumStationCode);
			swCkStationDailyReportOriginalSum.setTradeDate(insertObj.getTradeDate());
			swCkStationDailyReportOriginalSum.setSettleBeginTime(insertObj.getSettleBeginTime());
            swCkStationDailyReportOriginalSum.setSettleEndTime(insertObj.getSettleEndTime());
            swCkStationDailyReportOriginalSum.setDeptId(insertObj.getDeptId());
            swCkStationDailyReportOriginalSum.setCreatorId(insertObj.getCreatorId());
            swCkStationDailyReportOriginalSum.setCreatorName(insertObj.getCreatorName());
			swCkStationDailyReportOriginalSum.setConfirmStatus(insertObj.getConfirmStatus());
		    isExist = false;
		 }	

			Long tvmOneTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketCash();
			Long tvmOneTicketAlipaySum =isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketAlipay();
			Long tvmOneTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketWechat();
			Long tvmOneTicketBankSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketBank();
			Long tvmSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmSubTotal();
			
			Long bomOneTicketCashlSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketCash();
			Long bomOnePosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOnePosAmount();
			Long bomOneTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketAlipay();
			Long bomOneTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketWechat();
			Long bomSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomSubTotal();


			Long prefabricatedTicketAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getPrefabricatedTicketAmount();
			Long prefabricatedTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getPrefabricatedTicketPosAmount();
			Long emergencyTicketAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getEmergencyTicketAmount();
			Long ticketCountingSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTicketCounting();
			
			Long dailyTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketCash();
			Long dailyTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketPosAmount();
			Long dailyTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketAlipay();
			Long dailyTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketWechat();
			Long dailyTicketCatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketCat();
			
			Long dailySubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailySubTotal();

			Long commemorativeTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketCash();
			Long commemorativeTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketPosAmount();
			Long commemorativeTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketAlipay();
			Long commemorativeTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketWechat();
			Long commemorativeTicketSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketSubTotal();
			
			Long appCommemorativeTicketSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getAppCommemorativeTicket();

			Long catTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketCash();
			Long catTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketPosAmount();
			Long catTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketAlipay();
			Long catTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketWechat();
			
			Long catTicketItvmCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmCash();
			Long catTicketItvmAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmAlipay();
			Long catTicketItvmWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmWechat();
			Long catTicketItvmBankSum =isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmBank();
			Long catSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatSubTotal();
            //长安通刷卡消费 特殊处理 只有总计
            BigDecimal catTicketPayCardSum = isExist==false?new BigDecimal("0"):this.baseMapper.getCatTicketPayCardSum(initObj).get("catTicketPayCardSum");
			 //交通一卡通   特殊处理 只有总计   
            BigDecimal allOneTrafficCardSum = isExist==false?new BigDecimal("0"):this.baseMapper.getAllOneTrafficCardSum(initObj).get("allOneTrafficCardSum");
			
			Long onlineTicketSalesSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getOnlineTicketSales();
			Long qrCodeTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketAlipay();
			Long qrCodeTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechat();
			Long qrCodeTicketUnionpaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketUnionpay();
			Long qrCodeTicketAppSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketApp();
			Long qrCodeTicketWechatappDiscountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechatappDiscount();
			Long qrCodeTicketWechatappSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechatapp();		
			Long qrCodeSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeSubTotal();

			Long faceRecognitionTicketBankSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getFaceRecognitionTicketBank();

			Long qrConnectivityAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivityAlipay();
			Long qrConnectivityWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivityWechat();
			Long qrConnectivitySubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivitySubTotal();

			
			Long stationTicketLongCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationTicketLongCash();
			Long stationTicketShortCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationTicketShortCash();
			Long stationCompensationSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationCompensation();
			Long releasePettyCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getReleasePettyCash();
			Long subTotaPosSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getSubTotaPos();
			Long settlementAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getSettlementAmount();
            BigDecimal subTotaSum = isExist==false?new BigDecimal("0"):swCkStationDailyReportOriginalSum.getSubTota();
         
                tvmOneTicketCashSum = tvmOneTicketCashSum + insertObj.getTvmOneTicketCash();
                tvmOneTicketAlipaySum = tvmOneTicketAlipaySum + insertObj.getTvmOneTicketAlipay();
                tvmOneTicketWechatSum = tvmOneTicketWechatSum + insertObj.getTvmOneTicketWechat();
                tvmOneTicketBankSum = tvmOneTicketBankSum + insertObj.getTvmOneTicketBank();
                tvmSubTotalSum = tvmSubTotalSum + insertObj.getTvmSubTotal();
                bomOneTicketCashlSum = bomOneTicketCashlSum + insertObj.getBomOneTicketCash();
				bomOnePosAmountSum = bomOnePosAmountSum + insertObj.getBomOnePosAmount();
                bomOneTicketAlipaySum = bomOneTicketAlipaySum + insertObj.getBomOneTicketAlipay();

                bomOneTicketWechatSum = bomOneTicketWechatSum + insertObj.getBomOneTicketWechat();
                bomSubTotalSum = bomSubTotalSum + insertObj.getBomSubTotal();
                prefabricatedTicketAmountSum = prefabricatedTicketAmountSum + insertObj.getPrefabricatedTicketAmount();
				prefabricatedTicketPosAmountSum = prefabricatedTicketPosAmountSum + insertObj.getPrefabricatedTicketPosAmount();
                emergencyTicketAmountSum = emergencyTicketAmountSum + insertObj.getEmergencyTicketAmount();
                ticketCountingSum = ticketCountingSum + insertObj.getTicketCounting();
                dailyTicketCashSum = dailyTicketCashSum + insertObj.getDailyTicketCash();
				dailyTicketPosAmountSum = dailyTicketPosAmountSum + insertObj.getDailyTicketPosAmount();
                dailyTicketAlipaySum = dailyTicketAlipaySum + insertObj.getDailyTicketAlipay();
                dailyTicketWechatSum = dailyTicketWechatSum + insertObj.getDailyTicketWechat();
				dailyTicketCatSum = dailyTicketCatSum + insertObj.getDailyTicketCat();
                dailySubTotalSum = dailySubTotalSum + insertObj.getDailySubTotal();
               
				commemorativeTicketCashSum = commemorativeTicketCashSum + insertObj.getCommemorativeTicketCash();
				commemorativeTicketPosAmountSum = commemorativeTicketPosAmountSum + insertObj.getCommemorativeTicketPosAmount();
                commemorativeTicketAlipaySum = commemorativeTicketAlipaySum + insertObj.getCommemorativeTicketAlipay();
                commemorativeTicketWechatSum = commemorativeTicketWechatSum + insertObj.getCommemorativeTicketWechat();
                commemorativeTicketSubTotalSum = commemorativeTicketSubTotalSum + insertObj.getCommemorativeTicketSubTotal();
                appCommemorativeTicketSum = appCommemorativeTicketSum + insertObj.getAppCommemorativeTicket();

                catTicketCashSum = catTicketCashSum + insertObj.getCatTicketCash();
				catTicketPosAmountSum = catTicketPosAmountSum + insertObj.getCatTicketPosAmount();
                catTicketAlipaySum = catTicketAlipaySum + insertObj.getCatTicketAlipay();
                catTicketWechatSum = catTicketWechatSum + insertObj.getCatTicketWechat();
                catTicketItvmCashSum = catTicketItvmCashSum + insertObj.getCatTicketItvmCash();
                catTicketItvmAlipaySum = catTicketItvmAlipaySum + insertObj.getCatTicketItvmAlipay();
                catTicketItvmWechatSum = catTicketItvmWechatSum + insertObj.getCatTicketItvmWechat();
                catTicketItvmBankSum = catTicketItvmBankSum + insertObj.getCatTicketItvmBank();
                catSubTotalSum = catSubTotalSum + insertObj.getCatSubTotal();

                onlineTicketSalesSum = onlineTicketSalesSum + insertObj.getOnlineTicketSales();
                qrCodeTicketAlipaySum = qrCodeTicketAlipaySum + insertObj.getQrCodeTicketAlipay();
                qrCodeTicketWechatSum = qrCodeTicketWechatSum + insertObj.getQrCodeTicketWechat();
                qrCodeTicketUnionpaySum = qrCodeTicketUnionpaySum + insertObj.getQrCodeTicketUnionpay();
				qrCodeTicketAppSum = qrCodeTicketAppSum + insertObj.getQrCodeTicketApp();
				qrCodeTicketWechatappDiscountSum = qrCodeTicketWechatappDiscountSum + insertObj.getQrCodeTicketWechatappDiscount();
				qrCodeTicketWechatappSum = qrCodeTicketWechatappSum + insertObj.getQrCodeTicketWechatapp();
                qrCodeSubTotalSum = qrCodeSubTotalSum + insertObj.getQrCodeSubTotal();
                faceRecognitionTicketBankSum = faceRecognitionTicketBankSum + insertObj.getFaceRecognitionTicketBank();
                
				qrConnectivityAlipaySum = qrConnectivityAlipaySum +insertObj.getQrConnectivityAlipay();
				qrConnectivityWechatSum = qrConnectivityWechatSum +insertObj.getQrConnectivityWechat();
				qrConnectivitySubTotalSum = qrConnectivitySubTotalSum +insertObj.getQrConnectivitySubTotal();
				
                stationTicketLongCashSum = stationTicketLongCashSum + insertObj.getStationTicketLongCash();
                stationTicketShortCashSum = stationTicketShortCashSum + insertObj.getStationTicketShortCash();
                stationCompensationSum = stationCompensationSum + insertObj.getStationCompensation();
                releasePettyCashSum = releasePettyCashSum + insertObj.getReleasePettyCash();
				subTotaPosSum = subTotaPosSum + insertObj.getSubTotaPos();
                settlementAmountSum = settlementAmountSum + insertObj.getSettlementAmount();
                subTotaSum = subTotaSum.add(insertObj.getSubTota());
           
        swCkStationDailyReportOriginalSum.setTvmOneTicketCash(tvmOneTicketCashSum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketAlipay(tvmOneTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketWechat(tvmOneTicketWechatSum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketBank(tvmOneTicketBankSum);
        swCkStationDailyReportOriginalSum.setTvmSubTotal(tvmSubTotalSum);

        swCkStationDailyReportOriginalSum.setBomOneTicketCash(bomOneTicketCashlSum);
		swCkStationDailyReportOriginalSum.setBomOnePosAmount(bomOnePosAmountSum);
        swCkStationDailyReportOriginalSum.setBomOneTicketAlipay(bomOneTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setBomOneTicketWechat(bomOneTicketWechatSum);
        swCkStationDailyReportOriginalSum.setBomSubTotal(bomSubTotalSum);
       
		swCkStationDailyReportOriginalSum.setPrefabricatedTicketAmount(prefabricatedTicketAmountSum);
		swCkStationDailyReportOriginalSum.setPrefabricatedTicketPosAmount(prefabricatedTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setEmergencyTicketAmount(emergencyTicketAmountSum);
        swCkStationDailyReportOriginalSum.setTicketCounting(ticketCountingSum);
        
		swCkStationDailyReportOriginalSum.setDailyTicketCash(dailyTicketCashSum);
		swCkStationDailyReportOriginalSum.setDailyTicketPosAmount(dailyTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setDailyTicketAlipay(dailyTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setDailyTicketWechat(dailyTicketWechatSum);
	    swCkStationDailyReportOriginalSum.setDailyTicketCat(dailyTicketCatSum);
        swCkStationDailyReportOriginalSum.setDailySubTotal(dailySubTotalSum);

		swCkStationDailyReportOriginalSum.setCommemorativeTicketCash(commemorativeTicketCashSum);
		swCkStationDailyReportOriginalSum.setCommemorativeTicketPosAmount(commemorativeTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketAlipay(commemorativeTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketWechat(commemorativeTicketWechatSum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketSubTotal(commemorativeTicketSubTotalSum);

        swCkStationDailyReportOriginalSum.setAppCommemorativeTicket(appCommemorativeTicketSum);
        swCkStationDailyReportOriginalSum.setCatTicketCash(catTicketCashSum);
		swCkStationDailyReportOriginalSum.setCatTicketPosAmount(catTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setCatTicketAlipay(catTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setCatTicketWechat(catTicketWechatSum);
        
		swCkStationDailyReportOriginalSum.setCatTicketItvmCash(catTicketItvmCashSum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmAlipay(catTicketItvmAlipaySum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmWechat(catTicketItvmWechatSum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmBank(catTicketItvmBankSum);
        swCkStationDailyReportOriginalSum.setCatSubTotal(catSubTotalSum);

        //长安通刷卡消费，交通一卡通，总计的收入小计会加上该两项值        
        swCkStationDailyReportOriginalSum.setCatTicketPayCard(catTicketPayCardSum);
		swCkStationDailyReportOriginalSum.setAllOneTrafficCard(allOneTrafficCardSum);
		

        swCkStationDailyReportOriginalSum.setOnlineTicketSales(onlineTicketSalesSum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketAlipay(qrCodeTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketWechat(qrCodeTicketWechatSum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketUnionpay(qrCodeTicketUnionpaySum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketApp(qrCodeTicketAppSum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketWechatappDiscount(qrCodeTicketWechatappDiscountSum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketWechatapp(qrCodeTicketWechatappSum);
        swCkStationDailyReportOriginalSum.setQrCodeSubTotal(qrCodeSubTotalSum);

        swCkStationDailyReportOriginalSum.setFaceRecognitionTicketBank(faceRecognitionTicketBankSum);  
		
		swCkStationDailyReportOriginalSum.setQrConnectivityAlipay(qrConnectivityAlipaySum);
		swCkStationDailyReportOriginalSum.setQrConnectivityWechat(qrConnectivityWechatSum);
		swCkStationDailyReportOriginalSum.setQrConnectivitySubTotal(qrConnectivitySubTotalSum);		

        swCkStationDailyReportOriginalSum.setStationTicketLongCash(stationTicketLongCashSum);
        swCkStationDailyReportOriginalSum.setStationTicketShortCash(stationTicketShortCashSum);
        swCkStationDailyReportOriginalSum.setStationCompensation(stationCompensationSum);

        swCkStationDailyReportOriginalSum.setReleasePettyCash(releasePettyCashSum);
		swCkStationDailyReportOriginalSum.setSubTotaPos(subTotaPosSum);
        swCkStationDailyReportOriginalSum.setSettlementAmount(settlementAmountSum);
		if(!isExist){//不存在，只算一次相加
		   subTotaSum = subTotaSum.add(catTicketPayCardSum).add(allOneTrafficCardSum);
		}
        swCkStationDailyReportOriginalSum.setSubTota(subTotaSum);        
		//最后重新放进去
		 mapSumLine.put(insertObj.getVlineCode()+","+insertObj.getTradeDate(),swCkStationDailyReportOriginalSum);
     }
	
	
	 /**
         * 原始表插入或者更新按线路每日汇总值
         * @param
         * @return
         */
    private void insertOrUpdateDaySum(Map<String,SwCkStationDailyReportOriginal> mapSumLine,SwCkStationDailyReportOriginal insertObj)  {
	     //根据线路和日期获取汇总表的合计对象
		 boolean isExist = true;
		 SwCkStationDailyReportOriginal swCkStationDailyReportOriginalSum = mapSumLine.get(insertObj.getVlineCode()+","+insertObj.getTradeDate());
		 
		 if(swCkStationDailyReportOriginalSum ==null){
		    //不存在准备基本数据
			swCkStationDailyReportOriginalSum = new   SwCkStationDailyReportOriginal();	
            swCkStationDailyReportOriginalSum.setLineCode(insertObj.getVlineCode());
			swCkStationDailyReportOriginalSum.setStationCode(sumStationCode);
			swCkStationDailyReportOriginalSum.setTradeDate(insertObj.getTradeDate());
			swCkStationDailyReportOriginalSum.setSettleBeginTime(insertObj.getSettleBeginTime());
            swCkStationDailyReportOriginalSum.setSettleEndTime(insertObj.getSettleEndTime());
            swCkStationDailyReportOriginalSum.setDeptId(insertObj.getDeptId());
            swCkStationDailyReportOriginalSum.setCreatorId(insertObj.getCreatorId());
            swCkStationDailyReportOriginalSum.setCreatorName(insertObj.getCreatorName());
			swCkStationDailyReportOriginalSum.setConfirmStatus(insertObj.getConfirmStatus());
		    isExist = false;
		 }	

			Long tvmOneTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketCash();
			Long tvmOneTicketAlipaySum =isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketAlipay();
			Long tvmOneTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketWechat();
			Long tvmOneTicketBankSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmOneTicketBank();
			Long tvmSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTvmSubTotal();
			
			Long bomOneTicketCashlSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketCash();
			Long bomOnePosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOnePosAmount();
			Long bomOneTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketAlipay();
			Long bomOneTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomOneTicketWechat();
			Long bomSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getBomSubTotal();


			Long prefabricatedTicketAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getPrefabricatedTicketAmount();
			Long prefabricatedTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getPrefabricatedTicketPosAmount();
			
			Long emergencyTicketAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getEmergencyTicketAmount();
			Long ticketCountingSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getTicketCounting();
			
			Long dailyTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketCash();
			Long dailyTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketPosAmount();
			Long dailyTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketAlipay();
			Long dailyTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketWechat();
			Long dailyTicketCatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailyTicketCat();
			
			Long dailySubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getDailySubTotal();

			Long commemorativeTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketCash();
			Long commemorativeTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketPosAmount();
			Long commemorativeTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketAlipay();
			Long commemorativeTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketWechat();
			Long commemorativeTicketSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCommemorativeTicketSubTotal();
			
			Long appCommemorativeTicketSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getAppCommemorativeTicket();

			Long catTicketCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketCash();
			Long catTicketPosAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketPosAmount();
			Long catTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketAlipay();
			Long catTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketWechat();
			
			Long catTicketItvmCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmCash();
			Long catTicketItvmAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmAlipay();
			Long catTicketItvmWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmWechat();
			Long catTicketItvmBankSum =isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatTicketItvmBank();
			Long catSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getCatSubTotal();
            //长安通刷卡消费 特殊处理 只有总计
            BigDecimal catTicketPayCardSum = isExist==false?new BigDecimal("0"):this.baseMapper.getCatTicketPayCardSum(insertObj).get("catTicketPayCardSum");
			 //交通一卡通   特殊处理 只有总计   
            BigDecimal allOneTrafficCardSum = isExist==false?new BigDecimal("0"):this.baseMapper.getAllOneTrafficCardSum(insertObj).get("allOneTrafficCardSum");
			
			Long onlineTicketSalesSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getOnlineTicketSales();
			Long qrCodeTicketAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketAlipay();
			Long qrCodeTicketWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechat();
			Long qrCodeTicketUnionpaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketUnionpay();
			Long qrCodeTicketAppSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketApp();
			
			Long qrCodeTicketWechatappDiscountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechatappDiscount();
			Long qrCodeTicketWechatappSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeTicketWechatapp();	
			
			Long qrCodeSubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrCodeSubTotal();
			Long faceRecognitionTicketBankSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getFaceRecognitionTicketBank();

			Long qrConnectivityAlipaySum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivityAlipay();
			Long qrConnectivityWechatSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivityWechat();
			Long qrConnectivitySubTotalSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getQrConnectivitySubTotal();


			Long stationTicketLongCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationTicketLongCash();
			Long stationTicketShortCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationTicketShortCash();
			Long stationCompensationSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getStationCompensation();
			Long releasePettyCashSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getReleasePettyCash();
			Long subTotaPosSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getSubTotaPos();
			Long settlementAmountSum = isExist==false?new Long(0L):swCkStationDailyReportOriginalSum.getSettlementAmount();
            BigDecimal subTotaSum = isExist==false?new BigDecimal("0"):swCkStationDailyReportOriginalSum.getSubTota();
         
                tvmOneTicketCashSum = tvmOneTicketCashSum + insertObj.getTvmOneTicketCash();
                tvmOneTicketAlipaySum = tvmOneTicketAlipaySum + insertObj.getTvmOneTicketAlipay();
                tvmOneTicketWechatSum = tvmOneTicketWechatSum + insertObj.getTvmOneTicketWechat();
                tvmOneTicketBankSum = tvmOneTicketBankSum + insertObj.getTvmOneTicketBank();
                tvmSubTotalSum = tvmSubTotalSum + insertObj.getTvmSubTotal();
                bomOneTicketCashlSum = bomOneTicketCashlSum + insertObj.getBomOneTicketCash();
				bomOnePosAmountSum = bomOnePosAmountSum + insertObj.getBomOnePosAmount();
                bomOneTicketAlipaySum = bomOneTicketAlipaySum + insertObj.getBomOneTicketAlipay();

                bomOneTicketWechatSum = bomOneTicketWechatSum + insertObj.getBomOneTicketWechat();
                bomSubTotalSum = bomSubTotalSum + insertObj.getBomSubTotal();
                prefabricatedTicketAmountSum = prefabricatedTicketAmountSum + insertObj.getPrefabricatedTicketAmount();
				prefabricatedTicketPosAmountSum = prefabricatedTicketPosAmountSum + insertObj.getPrefabricatedTicketPosAmount();
                emergencyTicketAmountSum = emergencyTicketAmountSum + insertObj.getEmergencyTicketAmount();
                ticketCountingSum = ticketCountingSum + insertObj.getTicketCounting();
                dailyTicketCashSum = dailyTicketCashSum + insertObj.getDailyTicketCash();
				dailyTicketPosAmountSum = dailyTicketPosAmountSum + insertObj.getDailyTicketPosAmount();
                dailyTicketAlipaySum = dailyTicketAlipaySum + insertObj.getDailyTicketAlipay();
                dailyTicketWechatSum = dailyTicketWechatSum + insertObj.getDailyTicketWechat();
				dailyTicketCatSum = dailyTicketCatSum + insertObj.getDailyTicketCat();
                dailySubTotalSum = dailySubTotalSum + insertObj.getDailySubTotal();
               
				commemorativeTicketCashSum = commemorativeTicketCashSum + insertObj.getCommemorativeTicketCash();
				commemorativeTicketPosAmountSum = commemorativeTicketPosAmountSum + insertObj.getCommemorativeTicketPosAmount();
                commemorativeTicketAlipaySum = commemorativeTicketAlipaySum + insertObj.getCommemorativeTicketAlipay();
                commemorativeTicketWechatSum = commemorativeTicketWechatSum + insertObj.getCommemorativeTicketWechat();
                commemorativeTicketSubTotalSum = commemorativeTicketSubTotalSum + insertObj.getCommemorativeTicketSubTotal();
                appCommemorativeTicketSum = appCommemorativeTicketSum + insertObj.getAppCommemorativeTicket();

                catTicketCashSum = catTicketCashSum + insertObj.getCatTicketCash();
				catTicketPosAmountSum = catTicketPosAmountSum + insertObj.getCatTicketPosAmount();
                catTicketAlipaySum = catTicketAlipaySum + insertObj.getCatTicketAlipay();
                catTicketWechatSum = catTicketWechatSum + insertObj.getCatTicketWechat();
                catTicketItvmCashSum = catTicketItvmCashSum + insertObj.getCatTicketItvmCash();
                catTicketItvmAlipaySum = catTicketItvmAlipaySum + insertObj.getCatTicketItvmAlipay();
                catTicketItvmWechatSum = catTicketItvmWechatSum + insertObj.getCatTicketItvmWechat();
                catTicketItvmBankSum = catTicketItvmBankSum + insertObj.getCatTicketItvmBank();
                catSubTotalSum = catSubTotalSum + insertObj.getCatSubTotal();

                onlineTicketSalesSum = onlineTicketSalesSum + insertObj.getOnlineTicketSales();
                qrCodeTicketAlipaySum = qrCodeTicketAlipaySum + insertObj.getQrCodeTicketAlipay();
                qrCodeTicketWechatSum = qrCodeTicketWechatSum + insertObj.getQrCodeTicketWechat();
                qrCodeTicketUnionpaySum = qrCodeTicketUnionpaySum + insertObj.getQrCodeTicketUnionpay();
				qrCodeTicketAppSum = qrCodeTicketAppSum + insertObj.getQrCodeTicketApp();
				qrCodeTicketWechatappDiscountSum = qrCodeTicketWechatappDiscountSum + insertObj.getQrCodeTicketWechatappDiscount();
				qrCodeTicketWechatappSum = qrCodeTicketWechatappSum + insertObj.getQrCodeTicketWechatapp();
                qrCodeSubTotalSum = qrCodeSubTotalSum + insertObj.getQrCodeSubTotal();
                faceRecognitionTicketBankSum = faceRecognitionTicketBankSum + insertObj.getFaceRecognitionTicketBank();

				qrConnectivityAlipaySum = qrConnectivityAlipaySum +insertObj.getQrConnectivityAlipay();
				qrConnectivityWechatSum = qrConnectivityWechatSum +insertObj.getQrConnectivityWechat();
				qrConnectivitySubTotalSum = qrConnectivitySubTotalSum +insertObj.getQrConnectivitySubTotal();

                stationTicketLongCashSum = stationTicketLongCashSum + insertObj.getStationTicketLongCash();
                stationTicketShortCashSum = stationTicketShortCashSum + insertObj.getStationTicketShortCash();
                stationCompensationSum = stationCompensationSum + insertObj.getStationCompensation();
                releasePettyCashSum = releasePettyCashSum + insertObj.getReleasePettyCash();
				subTotaPosSum = subTotaPosSum + insertObj.getSubTotaPos();
                settlementAmountSum = settlementAmountSum + insertObj.getSettlementAmount();				
                subTotaSum = subTotaSum.add(insertObj.getSubTota());
           
        swCkStationDailyReportOriginalSum.setTvmOneTicketCash(tvmOneTicketCashSum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketAlipay(tvmOneTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketWechat(tvmOneTicketWechatSum);
        swCkStationDailyReportOriginalSum.setTvmOneTicketBank(tvmOneTicketBankSum);
        swCkStationDailyReportOriginalSum.setTvmSubTotal(tvmSubTotalSum);

        swCkStationDailyReportOriginalSum.setBomOneTicketCash(bomOneTicketCashlSum);
		swCkStationDailyReportOriginalSum.setBomOnePosAmount(bomOnePosAmountSum);
        swCkStationDailyReportOriginalSum.setBomOneTicketAlipay(bomOneTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setBomOneTicketWechat(bomOneTicketWechatSum);
        swCkStationDailyReportOriginalSum.setBomSubTotal(bomSubTotalSum);
       
		swCkStationDailyReportOriginalSum.setPrefabricatedTicketAmount(prefabricatedTicketAmountSum);
		swCkStationDailyReportOriginalSum.setPrefabricatedTicketPosAmount(prefabricatedTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setEmergencyTicketAmount(emergencyTicketAmountSum);
        swCkStationDailyReportOriginalSum.setTicketCounting(ticketCountingSum);
        
		swCkStationDailyReportOriginalSum.setDailyTicketCash(dailyTicketCashSum);
		swCkStationDailyReportOriginalSum.setDailyTicketPosAmount(dailyTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setDailyTicketAlipay(dailyTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setDailyTicketWechat(dailyTicketWechatSum);
        swCkStationDailyReportOriginalSum.setDailySubTotal(dailySubTotalSum);

		swCkStationDailyReportOriginalSum.setCommemorativeTicketCash(commemorativeTicketCashSum);
		swCkStationDailyReportOriginalSum.setCommemorativeTicketPosAmount(commemorativeTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketAlipay(commemorativeTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketWechat(commemorativeTicketWechatSum);
        swCkStationDailyReportOriginalSum.setCommemorativeTicketSubTotal(commemorativeTicketSubTotalSum);

        swCkStationDailyReportOriginalSum.setAppCommemorativeTicket(appCommemorativeTicketSum);
        swCkStationDailyReportOriginalSum.setCatTicketCash(catTicketCashSum);
		swCkStationDailyReportOriginalSum.setCatTicketPosAmount(catTicketPosAmountSum);
        swCkStationDailyReportOriginalSum.setCatTicketAlipay(catTicketAlipaySum);
		swCkStationDailyReportOriginalSum.setDailyTicketCat(dailyTicketCatSum);
        swCkStationDailyReportOriginalSum.setCatTicketWechat(catTicketWechatSum);
        
		swCkStationDailyReportOriginalSum.setCatTicketItvmCash(catTicketItvmCashSum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmAlipay(catTicketItvmAlipaySum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmWechat(catTicketItvmWechatSum);
        swCkStationDailyReportOriginalSum.setCatTicketItvmBank(catTicketItvmBankSum);
        swCkStationDailyReportOriginalSum.setCatSubTotal(catSubTotalSum);

        //长安通刷卡消费，交通一卡通，总计的收入小计会加上该两项值        
        swCkStationDailyReportOriginalSum.setCatTicketPayCard(catTicketPayCardSum);
		swCkStationDailyReportOriginalSum.setAllOneTrafficCard(allOneTrafficCardSum);
		

        swCkStationDailyReportOriginalSum.setOnlineTicketSales(onlineTicketSalesSum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketAlipay(qrCodeTicketAlipaySum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketWechat(qrCodeTicketWechatSum);
        swCkStationDailyReportOriginalSum.setQrCodeTicketUnionpay(qrCodeTicketUnionpaySum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketApp(qrCodeTicketAppSum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketWechatappDiscount(qrCodeTicketWechatappDiscountSum);
		swCkStationDailyReportOriginalSum.setQrCodeTicketWechatapp(qrCodeTicketWechatappSum);
        swCkStationDailyReportOriginalSum.setQrCodeSubTotal(qrCodeSubTotalSum);

        swCkStationDailyReportOriginalSum.setFaceRecognitionTicketBank(faceRecognitionTicketBankSum); 
		
		swCkStationDailyReportOriginalSum.setQrConnectivityAlipay(qrConnectivityAlipaySum);
		swCkStationDailyReportOriginalSum.setQrConnectivityWechat(qrConnectivityWechatSum);
		swCkStationDailyReportOriginalSum.setQrConnectivitySubTotal(qrConnectivitySubTotalSum);		

        swCkStationDailyReportOriginalSum.setStationTicketLongCash(stationTicketLongCashSum);
        swCkStationDailyReportOriginalSum.setStationTicketShortCash(stationTicketShortCashSum);
        swCkStationDailyReportOriginalSum.setStationCompensation(stationCompensationSum);

        swCkStationDailyReportOriginalSum.setReleasePettyCash(releasePettyCashSum);
		swCkStationDailyReportOriginalSum.setSubTotaPos(subTotaPosSum);
        swCkStationDailyReportOriginalSum.setSettlementAmount(settlementAmountSum);
		if(!isExist){//不存在，只算一次相加
		   subTotaSum = subTotaSum.add(catTicketPayCardSum).add(allOneTrafficCardSum);
		}
        swCkStationDailyReportOriginalSum.setSubTota(subTotaSum);        
		//最后重新放进去
		 mapSumLine.put(insertObj.getVlineCode()+","+insertObj.getTradeDate(),swCkStationDailyReportOriginalSum);
       	}

    private Long getLongValue( List<Map<String,Object>> listMap,String stationCode,String lineCode,String tradeDate,String key) {
        if(listMap == null || listMap.isEmpty()) {
            return 0L;
        }
        for (Map<String,Object> map : listMap){
            if(stationCode.equals(map.get("stationCode")) && lineCode.equals(map.get("lineCode")) && tradeDate.equals(map.get("tradeDate"))) {
                return (Long)map.get(key);
            }
        }
        return 0L;
    }
}
